﻿@using CodeGenerator.Core
@using System.Text
@{
    BuildHCodeCreate model = Model;
}
$(function () {
    InitialPage();
    GetGrid();
});
//初始化页面
function InitialPage() {
    //resize重设(表格、树形)宽高
    $(window).resize(function (e) {
        window.setTimeout(function () {
            $('#gridTable').setGridWidth(($('.gridPanel').width()));
            $("#gridTable").setGridHeight($(window).height() - 150);
        }, 200);
        e.stopPropagation();
    });
}
//加载表格
function GetGrid() {
    var selectedRowIndex = 0;
    $('#gridTable').jqGrid({
        url: "/Framework/@(model.Name)/GetPageList",
        datatype: "json",
        height: $(window).height() - 150,
        autowidth: true,
        colModel: [
            @foreach (CreateListCode column in model.ListCode)
            {
                if(column.Show)
                {
                    string width = "";
                    if (column.Width > 0)
                    {
                        width = ",width: " + column.Width + "";
                    }
                    if (column.Format == "日期")
                    {
                    @:{
                    @:label: "@(column.Lable)", name: "@(column.Field)", index: "@(column.Field)"@width, align: "@(column.Align)", hidden: @(column.Hidden), sortable: @(column.Sortable) ,
                    @:formatter: "date", formatoptions: { srcformat: 'Y-m-d H:i', newformat: 'Y-m-d H:i' }
                    @:},
                    }
                    else if (column.Format == "布尔")
                    {
                    @:{
                         @:label: "@(column.Lable)", name: "@(column.Field)", index: "@(column.Field)"@width, align: "@(column.Align)", hidden: @(column.Hidden), 
                         @:formatter: function (cellvalue, options, rowObject) {
                             @:if (cellvalue == '1') return "<i class=\"fa fa-check\"></i>";
                             @:if (cellvalue == '0') return "<i class=\"fa fa-close\"></i>";
                         @:}
                     @:},
                    }
                    else
                    {
                    @:{ label: "@(column.Lable)", name: "@(column.Field)", index: "@(column.Field)"@width, align: "@(column.Align)", hidden: @(column.Hidden), sortable: @(column.Sortable) },
                    }
                }
            }
        ],
        viewrecords: true,
        rowNum: 30,
        rowList: [30, 50, 100, 500, 1000],
        pager: "#gridPager",
        rownumbers: true,
        shrinkToFit: false,
        gridview: true
    });

    //查询事件
    $("#btn_Search").click(function () {
        $("#gridTable").jqGrid('setGridParam', {
            postData: { keywords: $("#keywords").val() },
        }).trigger('reloadGrid');
    });
    //查询回车
    $('#keywords').bind('keypress', function (event) {
        if (event.keyCode == "13") {
            $('#btn_Search').trigger("click");
        }
    });
}

//刷新
function windowload() {
    $("#gridTable").trigger("reloadGrid"); //重新载入
}